using Microsoft.AspNetCore.Mvc;
using Publicuse.Autofac;
using Publicuse.Entity;
using Publicuse.Interface.Extend;
using Publicuse.Interface;
using Geekeradmin.Authorize;
using Microsoft.AspNetCore.Authorization;
using Publicuse.Appication;
using Publicuse.Application;

namespace Geekeradmin.Controllers
{
    /// <summary>
    /// 文件上传管理
    /// </summary>
    [UserAuthorize("Admin")]
    public class FileController : BaseController
    {
        public FileController(
            IAutofaceInstance autoface,
            IMySqlSugarService mySqlSugar,
            IWebHostEnvironment webHost,
            Microsoft.Extensions.Options.IOptions<DBConnectionOption> options,
            IBaseServiceExt baseServiceExt
        )
            : base(autoface, mySqlSugar, webHost, options, baseServiceExt) { }

        /// <summary>
        /// 图片上传
        /// </summary>
        /// <returns></returns>
        [HttpPost("UploadImage"), AllowAnonymous]
        public async Task<JsonResult> UploadImage()
        {
            string path = webHost.WebRootPath;
            var files = Request.Form.Files;
            string loginUserCode = Request.Form["loginUserCode"];
            CommonResult result = await FileApplication.GetApplication(container).UploadImage(files, path, loginUserCode);
            return new JsonResult(result);
        }

    }
}
